<template>
	<view class="wrap">
		<u-waterfall v-model="flowList" ref="uWaterfall">
			<template v-slot:left="{ leftList }">
				<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
					<!-- 微信小程序需要hx2.8.11版本才支持在template中引入其他组件，比如下方的u-lazy-load组件 -->
					<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load>
					<view class="sex">{{item.sex}}</view>
					<view class="wechatNumber">微信号：{{item.wechatNumber}}</view>

				</view>
			</template>
			<template v-slot:right="{ rightList }">
				<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
					<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load>
					<view class="sex">{{item.sex}}</view>
					<view class="wechatNumber">微信号：{{item.wechatNumber}}</view>
				</view>
			</template>
		</u-waterfall>
		<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
	</view>
</template>

<script>
	import API from '@/api/api.js';
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				flowList: [],
				list: [{
						sex: 35,
						wechatNumber: '北国风光，千里冰封，万里雪飘',
						image: 'http://pic.sc.chinaz.com/Files/pic/pic9/202002/zzpic23327_s.jpg'
					},
					{
						sex: 75,
						wechatNumber: '望长城内外，惟余莽莽',
						image: 'http://pic.sc.chinaz.com/Files/pic/pic9/202002/zzpic23325_s.jpg'
					}
				],
				rankList: [],
				page: 1,
				isLastPage: false,
			};
		},
		onLoad() {
			this.getMineNode({
				size: 10
			});
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			// setTimeout(() => {
			// 	this.addRandomData();
			// 	this.loadStatus = 'loadmore';
			// }, 1000);
			if (!this.isLastPage) {
				this.getMineNode({
					size: 10,
					page: this.page
				})
			}
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			addRandomData() {
				// for (let i = 0; i < 10; i++) {
				// 	let index = this.$u.random(0, this.list.length - 1);
				// 	// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
				// 	let item = JSON.parse(JSON.stringify(this.list[index]));
				// 	item.id = this.$u.guid();
				// 	this.flowList.push(item);
				// }

				var data = {
					"page": 1,
					"isLastPage": false,
					"flowList": []
				}
				this.getMineNode(data)
			},
			getMineNode: function(data) {
				console.log(data)
				API.getMineSpot(data).then(res => {
						// console.log(res)
						if (res.content.length < 10) {
							this.isLastPage = true
						}
						this.page = this.page + 1
						// this.flowList = this.flowList.concat(res.content)
						for (let i = 0; i < res.content.length; i++) {
							this.flowList.push(res.content[i])
						}
						// this.flowList=res.content;
					})
					.catch(err => {
						console.log(err)
					})
			}
		}
	};
</script>

<style>
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
</style>

<style lang="scss" scoped>
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-img-wrap {}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.wechatNumber {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
		word-break: break-all;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #ffffff;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.sex {
		// font-size: 30rpx;
		// color: $u-type-error;
		// margin-top: 5px;

		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
		word-break: break-all;
	}
</style>
